import request from 'umi-request';

export async function getScorePage(params = {}, statusArray, type) {
  let status;
  if (type===0){
    status = params.status ? [params.status] : [0,1]
  }else {
    status = params.status ? [params.status] : [2,3]
  }
  return request('/hr-ssc/api/api-admin/score/getScorePage', {
    method: 'get',
    params: {
      pageNum: params.current,
      pageSize: params.pageSize,
      ...params,
      status,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function updateScoreStatus(id) {
  return request('/hr-ssc/api/api-admin/score/updateScoreStatus', {
    method: 'POST',
    params: {id}
  }).then((res) => {
    return  res;
  })
}

export async function updateScoreStop(id) {
  return request('/hr-ssc/api/api-admin/score/updateScoreStop', {
    method: 'GET',
    params: {id}
  }).then((res) => {
    return  res;
  })
}

export async function deleteScore(id) {
  return request('/hr-ssc/api/api-admin/score/deleteScore', {
    method: 'DELETE',
    params: {id}
  }).then((res) => {
    return  res;
  })
}

export async function getScoreInfo(id) {
  return request('/hr-ssc/api/api-admin/score/getScoreInfo', {
    method: 'get',
    params: {id}
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return null;
    }
  })
}

export async function getSelectProgram() {
  return request('/hr-ssc/api/api-admin/score/getSelectProgram', {
    method: 'get',
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return [];
    }
  })
}

export async function getScoreUpdateDetail(id) {
  return request('/hr-ssc/api/api-admin/score/getScoreUpdateDetail', {
    method: 'get',
    params: {id}
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return {};
    }
  })
}

export async function saveAndUpdateScore(params) {
  return request('/hr-ssc/api/api-admin/score/saveAndUpdateScore', {
    method: 'POST',
    data: params
  }).then((res) => {
    return  res;
  })
}

export async function getScoreWeightsInfo(id) {
  return request('/hr-ssc/api/api-admin/score/getScoreWeightsInfo', {
    method: 'POST',
    data: {id},
    requestType: 'form'
  }).then((res) => {
    if (res.flag) {
      return res.data;
    } else {
      return {};
    }
  })
}

export async function SaveAndUpdateScoreWeightsInfo(params) {
  return request('/hr-ssc/api/api-admin/score/SaveAndUpdateScoreWeightsInfo', {
    method: 'POST',
    data: params
  }).then((res) => {
    return res;
  })
}

export async function saveScoreWeightsInfoAndScoreProgram(params) {
  return request('/hr-ssc/api/api-admin/score/saveScoreWeightsInfoAndScoreProgram', {
    method: 'POST',
    data: params
  }).then((res) => {
    return res;
  })
}

export function getEmployessInfoByCode(codes) {
  return request('/hr-ssc/api/api-admin/dimission/getEmployessInfoByCodeList', {
    method: 'get',
    params: {code: codes}
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return {notFoundStr:'系统出错,请稍后重试!'}
  })
}

export function getSoreTopicScore(id) {
  return request('/hr-ssc/api/api-admin/score/getSoreTopicScore', {
    method: 'get',
    params: {id}
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return []
  })
}

export async function getScoreProgramAndTopic(id) {
  return request('/hr-ssc/api/api-admin/score/getScoreProgramAndTopic', {
    method: 'get',
    params: {id}
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return []
  })
}

export async function getScoreTopicList() {
  return request('/hr-ssc/api/api-admin/score/getScoreTopicList', {
    method: 'get'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }
    return []
  })
}

export async function saveAndUpdateScoreTopicInfo(params) {
  return request('/hr-ssc/api/api-admin/score/saveAndUpdateScoreTopicInfo', {
    method: 'POST',
    data: params
  }).then((res) => {
    return res;
  })
}

export async function saveSoreProgramTopic(params) {
  return request('/hr-ssc/api/api-admin/score/saveSoreProgramTopic', {
    method: 'POST',
    data: params
  }).then((res) => {
    return res;
  })
}
